import cv2

# 1. 读取图像
img = cv2.imread("../images/lena.png")

# 2. 选择感兴趣区域
x,y,w,h = cv2.selectROI("select roi", img)
roi_img = img[y:y+h, x:x+w]

# 3. 将1x1像素块的颜色 拓展到 10x10 或者 20x20像素块大小，模拟打马赛克效果
n = 10
for i in range(0, h, n):
    for j in range(0, w, n):
        color_1px = roi_img[i, j]
        roi_img[i:i+n, j:j+n] = color_1px

# 4. 将打马赛克的感兴趣区域，替换到原图上去
img[y:y+h, x:x+w] = roi_img

# 5. 显示图像
cv2.imshow("mosaic image", img)
cv2.waitKey(0)

